<?php
/**
 * Created by PhpStorm.
 * User: Tangyijun
 * Date: 2017/3/22
 * Time: 9:35
 */
namespace app\home\controller;
use app\models\Bases;

/**
 * Class Upload
 * @package app\home\controller
 */
class Upload extends Base{
    /**
     * @return \think\response\Json
     * 普通聊天室
     */
    public function upload(){
        header('Content-Type:text/html; charset=utf-8');
        try{
            $post = input('param.');
            $model = new Bases('chat');     //1是普通聊天
            $post['create_time'] = time();
            $file = request()->file('image');
            if(!$file)
                throw new \LogicException($file->getError(),10021);
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'.DS.'chat');// 移动到框架应用根目录/public/uploads/chat 目录下
            if(!$info)
                throw new \LogicException('创建目录失败',10022);
            $post['content'] = $info->getSaveName(); //获取文件名称

        }catch(\Exception $e){
            echo $e->getMessage();
        }
        echo DS.'uploads'.DS.'chat' .DS.$post['content'];
    }
}